Ext.namespace('SilverMapper');

SilverMapper.Timeline = function(config) {

	this.start = null;
	this.end = null;

	var store = new Ext.data.JsonStore({
			totalProperty: 'totalCount'
		,	root: 'records'
		,	idProperty: 'id'
		,	id: 'id'
		,	remoteSort: true
//		,	autoLoad: true
		,	baseParams: { task: 'recordsByYear' }
		,	fields: [
					{name: 'Date', type: 'date', dateFormat: 'Y-m-d' }
				,	{name: 'Layer0', type: 'int' }
				,	{name: 'Layer2', type: 'int' }
				,	{name: 'Layer1', type: 'int' }
			]
		,	proxy: new Ext.data.HttpProxy({
					url: 'api/silvermapper.php'
			})
	});

	Ext.apply(this, config, {
			id: 'sm-timeline'
		,	visualizationPkg: 'annotatedtimeline'
		,	store: store
		,	border: false
		,	visualizationCfg: {
					displayZoomButtons: false
//				,	legendPosition: 'newRow'
				,	allValuesSuffix: ' Records'
				,	scaleType: 'maximize'
			}
		,	listeners: {
			
					rangechange : function(e, panel, range) {
						this.start = range.start;
						this.end = range.end;
						if (this.refreshed) {
							this.refreshed = false;
						} else {
							Ext.getCmp('sm-map').getMarkers( 0, true );
						}
					}

				,	render: function() {
						this.mask = new Ext.LoadMask( this.body, {
								msg: Lang.Get('Core','general','map_loading')
						});
					}

			}
		,	columns: [{
					dataIndex: 'Date'
				,	label: 'Date'
			}, {
					dataIndex: 'Layer0'
				,	label: 'UW Herbarium (Introduced)'
			},{
					dataIndex: 'Layer2'
				,	label: 'UW Herbarium (Native)'
			},{
					dataIndex: 'Layer1'
				,	label: 'Noxious Weed Observations'
			}]
	});
						
	SilverMapper.Timeline.superclass.constructor.apply(this, arguments);

};

Ext.extend( SilverMapper.Timeline, Ext.ux.GVisualizationPanel, {
					 
		getYearValue: function( value ) {			
			if (this.start != null) {
				return( eval('this.' + value).format('Y') );
			}
			return('');
		}
		
	,	updateTimeline: function( sw_lat, sw_lng, ne_lat, ne_lng, layers, filters ) {

			this.store.load({ params: { 
					sw_lat: sw_lat
				,	sw_lng: sw_lng
				,	ne_lat: ne_lat
				,	ne_lng: ne_lng
				,	layers: layers
				,	filters: filters
			} });

			this.resetRange();

		}
		
	,	resetRange: function() {
			this.start = null;
			this.end = null;
		}
		
});